using System.Linq;
using Core.Contracts.Interfaces;

namespace Core.Features
{
    using System;
    using Base;
    using Contracts.Enums;
    using Resources;

    
    public sealed class MissileGuidanceFailure<T> : FeatureBase<object>
    {
        public MissileGuidanceFailure(){}

        public MissileGuidanceFailure(T value) 
            : base(value){ }
        /// <summary>
        /// Obtains the feature name
        /// </summary>
        public override string Name
        {
            get { return "Missile guidance failure"; }
        }
        /// <summary>
        /// Obtains the feature group
        /// </summary>
        public override FeatureGroupsEnum FeatureGroup{ get { return FeatureGroupsEnum.TargetingEquipment; } }
        /// <summary>
        /// Obtains the feature type
        /// </summary>
        public override FeaturesEnum FeatureType { get { return FeaturesEnum.MissileGuidanceFailure; } }
        /// <summary>
        /// Obtains or defines the feature unit
        /// </summary>
        public override string Unit { get { return Traduction.label_unit_percent; } }

        public override string FormattedValue
        {
            get { return String.Format("{0} {1}",IsModified ? (double) ModifiedValue*100 : (double) Value*100, Unit); }
        }

        public override void SetModifiedValue(IAgent agent, IRobot robot)
        {
            if (agent == null || robot == null) return;

            // bonus from extensions
            double temp = (double)Value - Math.Abs(agent.Extensions.SumModifiersValues(FeatureTypesEnum.Robot, this.FeatureType));

            ModifiedValue = IsRounded
                               ? Math.Round(temp, 0, MidpointRounding.AwayFromZero)
                               : Math.Round(temp, 2);
        }
    }
}